package com.asiainfo.complier.ui;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class JTitleItem extends JLabel {

	/**
	 * JTitleItem
	 */
	private static final long serialVersionUID = 6133172480102454448L;

	private Color borderColor = new Color(0x74, 0x7E, 0x89);

	private boolean selected;

	private JProperitesItem item;

	/**
	 * @return the item
	 */
	public JProperitesItem getItem() {
		return item;
	}

	/**
	 * @param item
	 *            the item to set
	 */
	public void setItem(JProperitesItem item) {
		this.item = item;
	}

	public JTitleItem(String title, JPanel parent) {
		super(title);
		int w = parent.getPreferredSize().width;
		setPreferredSize(new Dimension(w - 2, 26));
		this.addMouseListener(new MouseAdapter() {

			public void mouseExited(MouseEvent e) {
				setForeground(Color.black);
				selected = false;

			}

			public void mouseEntered(MouseEvent e) {
				selected = true;
				setForeground(Color.white);

			}
		});
		this.setBorder(new Border() {

			public void paintBorder(Component c, Graphics g, int x, int y,
					int width, int height) {
				g.setColor(borderColor);

				if (selected) {
					g.fillRect(-1, -1, getWidth() + 2, getHeight() - 1);
					setForeground(Color.white);
					g.setColor(Color.white);
					g.drawString(getText(), 15, getHeight() / 2);
				} else {
					g.drawRect(-1, -1, getWidth() + 2, getHeight() - 1);
					setForeground(Color.black);
				}
			}

			public boolean isBorderOpaque() {

				return true;
			}

			public Insets getBorderInsets(Component c) {

				return new Insets(1, 15, 1, 5);
			}
		});

	}

}
